package cn.mw.cmdb.entity.FinanceReport;

import cn.mw.cmdb.entity.PropertyTypeString;
import cn.mw.cmdb.enums.FinanceReportPropertyConstraintEnum;
import cn.mw.components.mongodb.anno.AutoId;
import cn.mw.components.mongodb.anno.CMDBProperty;
import com.alibaba.nacos.common.utils.CollectionUtils;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.data.mongodb.core.mapping.Document;

import java.util.List;

@Data
@Document("mw_cmdbmd_finance_report_dictionary")
@Schema(description = "金融元上报数据字典")
public class FinanceReportDictionaryInfo {
    @CMDBProperty(searchType = PropertyTypeString.ID, searchPrefix = "_")
    @AutoId
    @Schema(description = "id")
    private String id;

    @Schema(description = "关联通道")
    @CMDBProperty(searchType = PropertyTypeString.ID)
    private Integer channelId;

    @Schema(description = "分组ID")
    @CMDBProperty(searchType = PropertyTypeString.ID, keywordSearch = true)
    private String groupId;

    @Schema(description = "分组路径")
    @CMDBProperty(searchType = PropertyTypeString.ID, keywordSearch = true)
    private List<String> groupPath;

    @Schema(description = "名称")
    @CMDBProperty(searchType = PropertyTypeString.ID)
    private String fieldName;

    @Schema(description = "请求名")
    @CMDBProperty(searchType = PropertyTypeString.ID)
    private String facilityName;

    @CMDBProperty
    @Schema(description = "创建人")
    protected String creator;

    @CMDBProperty(searchType = PropertyTypeString.ID)
    @Schema(description = "创建时间")
    protected String createDate;

    @CMDBProperty
    @Schema(description = "修改人")
    protected String lastUpdatedBy;

    @CMDBProperty(searchType = PropertyTypeString.ID)
    @Schema(description = "修改时间")
    protected String lastUpdateDate;

    @Schema(description = "约束条件")
    @CMDBProperty
    private FinanceReportPropertyConstraintEnum constraint;

    public void setGroupPath(List<String> groupPath) {
        this.groupPath = groupPath;
        if (CollectionUtils.isNotEmpty(groupPath)) {
            this.groupId = groupPath.get(groupPath.size() - 1);
        }
    }
}
